﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
/*
        bool Agent = CheckAgent();
        if (Agent == true)
        {
            Response.Redirect("Link.aspx");
        }
        */
        Page.Title = "登录";
        string q=Request.QueryString["q"];
        if (q == "quit")
        {
            Session.Abandon();
            //清空
            Session.Clear();
            Response.Redirect("Login.aspx");
        }
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        //localhost.WebServiceGZ Web = new localhost.WebServiceGZ();
        scjrm.WebServiceGZ Web = new scjrm.WebServiceGZ();
        string username = UserName.Text;
        string password = PassWord.Text;
        string idcard = IdCard.Text;
        if (username == "" || password == "" || idcard == "")
        {
            MessageBox.Text = "账号、密码或身份证后四位为空";
        }
        string Note = "";
        string GetNote = Web.Login(username, password, idcard);
        string[] NoteArray = GetNote.Split('|');

        string LoginState = NoteArray[0].ToString();

        if (LoginState == "True")
        {
            Session["UID"] = GetNote;
            Session["ygbh"] = NoteArray[1].ToString();
            Session["xingming"] = NoteArray[2].ToString();
            Session["zjm"] = NoteArray[3].ToString();
            Session["kl"] = NoteArray[4].ToString();
            Session["idcards"] = NoteArray[5].ToString();
            Session["sexid"] = NoteArray[6].ToString();
            Session["csrq"] = NoteArray[7].ToString();
            Session["rsjbqyshj"] = NoteArray[8].ToString();
            Session["gl"] = NoteArray[9].ToString();
            Session["khyh"] = NoteArray[10].ToString();
            Session["yhzhh"] = NoteArray[11].ToString();
            Session["telephoneno"] = NoteArray[12].ToString();
            Session["state"] = NoteArray[13].ToString();
            Session["lzrq"] = NoteArray[14].ToString();
            Session["DepartmentName"] = NoteArray[15].ToString();
            Session["AppointmentName"] = NoteArray[16].ToString();
            Session["Photo"] = NoteArray[17].ToString();
            Session.Timeout = 15;
            Note = GetNote;
            if (password == "123")
            {
                Response.Redirect("Repass.aspx");
            }
            else
            {
                if (Session["Photo"].ToString() != "")
                {
                    Response.Redirect("Default.aspx");
                }
                else {
                    Response.Redirect("Photo.aspx");
                }
            }

        }
        else
        {
            Note = "登录失败，账号、密码或身份证后四位错误";
            Session.Abandon();
        }
        MessageBox.Text = Note;
    }

    public static bool CheckAgent()
    {
        bool flag = false;
        string agent = HttpContext.Current.Request.UserAgent;
        string[] keywords = { "Android", "Windows Phone", "MQQBrowser" };
        foreach (string item in keywords)
        {
            if (agent.Contains(item))
            {
                flag = true;
                break;
            }
        }
        //排除 Windows 桌面系统            
        if (agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains("compatible; MSIE 9.0;")))
        {
            flag = true;
        }
        //排除 苹果桌面系统                
        if (agent.Contains("Windows NT") && agent.Contains("Macintosh"))
        {
            flag = true;
        }
        return flag;
    }

    public static bool CheckAgentA()
    {
        bool flag = false;
        string agent = HttpContext.Current.Request.UserAgent;
        string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };
        //排除 Windows 桌面系统            
        if (!agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains("compatible; MSIE 9.0;")))
        {
            //排除 苹果桌面系统                
            if (!agent.Contains("Windows NT") && !agent.Contains("Macintosh"))
            {
                foreach (string item in keywords)
                {
                    if (agent.Contains(item))
                    {
                        flag = true;
                        break;
                    }
                }
            }
            flag = true;
        }
        return flag;
    }
}
